import Vue from 'vue'
import App from './App.vue'
import './assets/main.css'; // 引入全局样式文件
import VueRouter from 'vue-router'

import User from './views/SystemManagementUser.vue' 
import Log from './views/SystemManagementLog.vue' 

import Worker from './views/InputInformationWorker.vue' 
import Craft from './views/InputInformationCraft.vue' 
import Equipment from './views/InputInformationEquipment.vue' 
import Instrument from './views/InputInformationInstrument.vue' 
import Quality from './views/InputInformationQuality.vue' 
import Plan from './views/InputInformationPlan.vue' 
import Exception from './views/InputInformationException.vue' 

import Completetion from './views/pre-assessment_completetion.vue' 
import Schedule from './views/pre-assessment_schedule.vue' 

import generatingschedule from './views/generating_schedule.vue' 
import SearchToPlan from './views/SearchToPlan.vue' 
import generatingplan from './views/generating_plan.vue' 
import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';
import Login from './views/Login.vue'; 


import Home from './views/Home.vue' 


Vue.use(VueRouter)
Vue.use(ElementUI)

const router = new VueRouter({
  routes:[
    { path: '/user', component: User},
    { path: '/log', component: Log},
    { path: '/worker', component: Worker},
    { path: '/craft', component: Craft},
    { path: '/equipment', component: Equipment},
    { path: '/instrument', component: Instrument},
    { path: '/quality', component: Quality},
    { path: '/plan', component: Plan},
    { path: '/exception', component: Exception},
    { path: '/home', component: Home},
    { path: '/completetion', component: Completetion},
    { path: '/schedule', component: Schedule},
    { path: '/generatingplan', component: generatingplan},
    { path: '/generatingschedule', component: generatingschedule},
    { path: '/searchplan', component: SearchToPlan},
    { path: '/login', component: Login},
    
    
  ]


})
// 导航守卫，检查是否已登录
router.beforeEach((to, from, next) => {
  const publicPages = ['/login']; // 不需要验证的页面
  const authRequired = !publicPages.includes(to.path); // 需要验证的页面
  const loggedIn = localStorage.getItem('token'); // 检查 token 是否存在

  if (authRequired && !loggedIn) {
    // 如果访问需要验证的页面且没有登录，跳转到登录页面
    return next('/login');
  }
  
  next(); // 继续跳转
});
Vue.config.productionTip = false

new Vue({
  render: h => h(App),
  router
}).$mount('#app')
